package com.codeblock_;

public class CodeBlock01 {
    public static void main(String[] args) {
        Movie movie1 = new Movie("霸王别姬");
        Movie movie2 = new Movie(30, "陈凯歌");
        Movie movie3 = new Movie("霸王别姬", 30, "陈凯歌");
    }
}

class Movie{
    private String name;
    private double price;
    private String director;

    //3个构造器 ->重载
    //把三个构造器中相同的语句放入到一个代码块中
    //不论调用哪个构造器，创建对象，都会先调用代码块的内容
    //代码块的调用先于构造器


    {
        System.out.println("电影屏幕打开");
        System.out.println("广告开始");
        System.out.println("电影正式开始");
    }

    public Movie(String name) {
        System.out.println("Movie(String name)被调用");
        this.name = name;
    }

    public Movie(double price, String director) {
        System.out.println("Movie(double price, String director)被调用");
        this.price = price;
        this.director = director;
    }

    public Movie(String name, double price, String director) {
        System.out.println("Movie(String name, double price, String director)被调用");
        this.name = name;
        this.price = price;
        this.director = director;
    }
}
